/**
 * 
 */
package cungmua.vn.kiosk.activity;

import cungmua.vn.kiosk.AbstractActivity;
import cungmua.vn.kiosk.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;

/**
 * @author TrongNguyen
 * 
 */
public class SplashScreen extends AbstractActivity {

	protected int seconds = 3;
	Handler handler = new Handler();


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splashscreen);
		handler.post(runnable);
	}

	private Runnable runnable = new Runnable() {
		public void run() {
			long currentMilliseconds = System.currentTimeMillis();
			seconds--;
			if (seconds > 0) {
				handler.postAtTime(this, currentMilliseconds);
				handler.postDelayed(runnable, 1000);
			} else {
				Intent it = new Intent(SplashScreen.this, MainActivity.class);
				startActivity(it);
				handler.removeCallbacks(runnable);
				finish();
			}
		}
	};

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			handler.removeCallbacks(runnable);
			Intent it = new Intent(SplashScreen.this, MainActivity.class);
			startActivity(it);
			finish();
		}
		return true;
	}
}
